package com.weipai.springboot.module.dao.impl;

import com.weipai.springboot.model.Picture;
import com.weipai.springboot.model.PictureCategory;
import com.weipai.springboot.module.dao.PictureDao;
import com.weipai.springboot.module.mapper.PictureCategoryMapper;
import com.weipai.springboot.module.mapper.PictureMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;

import java.util.List;
import java.util.Map;

/**
 * @Author: 曹朋飞
 * @Date: 2018/08/27 17:29
 */
@Repository
public class PictureDaoImpl implements PictureDao{

    @Autowired
    private PictureMapper pictureMapper;
    @Autowired
    private PictureCategoryMapper categoryMapper;
    
    //通过图片的分类获取图片
    @Override
    public List<Map<String, Object>> getImgByPictureCategoryId(String id) {
        return pictureMapper.getImgByPictureCategoryId(id);
    }

    //图片的保存
    @Override
    public int savePicture(Picture picture) {
        return pictureMapper.insert(picture);
    }

    //通过图片id获取图片详情
    @Override
    public Picture getPictureById(Integer id) {
        return pictureMapper.selectByPrimaryKey(id);
    }

    //图片的删除
    @Override
    public int batchDeleteById(Integer[] id) {
        return pictureMapper.batchDeleteById(id);
    }

    //图片的修改
    @Override
    public int updatePicture(Picture picture) {
        return pictureMapper.updateByPrimaryKeySelective(picture);
    }

    //图片分类的保存
    @Override
    public int savePictureCategory(PictureCategory pictureCategory) {
        return categoryMapper.insert(pictureCategory);
    }

    //图片分类的修改
    @Override
    public int updatePictureCategory(Integer id, String categoryName) {
        return categoryMapper.updatePictureCategory(id, categoryName);
    }

    //获取图片分类的详情
    @Override
    public Map<String, Object> getPictureCategoryInfo(Integer id) {
        return categoryMapper.getPictureCategoryInfo(id);
    }

    //查看图片分类下是否关联图片
    @Override
    public int vertifiPicture(Integer id) {
        return pictureMapper.vertifiPicture(id);
    }

    //图片分类的删除
    @Override
    public int batchDeleteByCategoryId(Integer[] id) {
        return categoryMapper.batchDeleteByCategoryId(id);
    }

    //图片分类列表
    @Override
    public List<PictureCategory> pictureCategoryList() {
        return categoryMapper.pictureCategoryList();
    }
}
